package com.threeti.mecool.core.infrastructure.persistence;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.threeti.mecool.core.domain.model.acl.User;

public interface UserRepository extends JpaRepository<User, Long> {
  User findByloginName(String loginName);

  User findByloginNameAndPassword(String loginName, String password);
  
  @Modifying
  @Transactional
  @Query("update User u set u.password = ?3 where u.loginName = ?1 and u.password = ?2")
  int changePasswordByLoginNameAndOldPassword(String loginName, String oldPassword, String newPassword);
}
